export default {
  name: 'AddPlan',
  data () {
  	 return {
		nowStep:''
  	 }
  },
  beforeRouteLeave (to, from, next) {
  		// this.$store.commit('setaddPlanMaxStep',1);
		// this.$store.commit('setaddPlanNowStep',1);
		this.$store.commit('clearPlanStepPool');   
		sessionStorage.removeItem('campaign');
  		next();
  },
  mounted(){
	  if(!this.$route.query.step && this.stepPool.length==0){
		this.$store.commit('setPlanStepPool','base');
		this.nowStep='base';
		this.$router.push('/add_plan');
	  }
	  if(this.$route.query.step && this.stepPool.length==0){
		this.$store.commit('setPlanStepPool',this.$route.query.step);
		this.nowStep=this.$route.query.step;
	  }

  },
  computed:{
		// maxStep(){
		// 	return this.$store.state.addPlanMaxStep;
		// },
		// nowStep(){
		// 	return this.$store.state.addPlanNowStep;
		// },
		stepPool(){
			return this.$store.state.planAddStepPool;
		}
  },
  methods:{
  	setStep(i){
		 if(this.stepPool.findIndex((value)=>{return i==value})==-1){
			return;
		 }
		 if(this.nowStep==i){
			 return;
		 }
		 this.nowStep=i;
		  switch(i){
			  case'base' :
			  	this.$router.push({path:'/add_plan/baseMsg',query:{step:this.$route.query.step}});
			  break;
			  case 'unit':
			  	this.$router.push({path:'/add_plan/setunit',query:{step:this.$route.query.step}});
			  break;
			  case 'creative':
			  this.$router.push({path:'/add_plan/setcreative',query:{step:this.$route.query.step}});
			  break
		  }
  	}
  }
}